<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>后台管理模板</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
        <link rel="stylesheet" href="../../css/global.css" media="all">
        <link rel="stylesheet" type="text/css" href="http://www.jq22.com/jquery/font-awesome.4.6.0.css">
        <link rel="stylesheet" href="../../datatables/media/css/jquery.dataTables.css">
        <link rel="stylesheet" href="../../datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css">
    </head>
    <body>
        <div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #1aa094;">
            <!--头部导航-->
            <div class="layui-header header header-demo"></div>
            <!--左侧导航-->
            <div class="layui-side layui-bg-black" id="admin-side">
            </div>
            <!--右侧具体内容-->
            <div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;padding:20px" id="admin-body">
                <div class="title">资金管理</div>
                <hr/>
                <div class="select">
                    <select name="fundselect" lay-verify="" id="fundSequence">
                        <option value="">排序</option>
                        <option value="1">流入平台</option>
                        <option value="2">流出平台</option>
                        <option value="3">金额↑</option>
                        <option value="4">金额↓</option>
                        <option value="5">发生时间↑</option>
                        <option value="6">发生时间↓</option>
                    </select>
                </div>
                <div class="layui-form">
                    <table class="layui-table" id="fundTable">
                        <thead>
                            <tr>
                                <th><input type="checkbox" id="checkall" onchange="checkAll(this,'#fundTable')"></th>
                                <th>用户</th>
                                <th>资金流向</th>
                                <th>流动原因</th>
                                <th>金额</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><input type="checkbox" name="fundcheck"></td>
                                <td><img src="../../images/fems.jpg"><span>大灰狼</span></td>
                                <td>流入平台</td>
                                <td>发布订单</td>
                                <td>82</td>
                                <td>2017-6-30</td>
                                <td><div class="layui-btn layui-btn-danger  layui-btn-small fundclose">冻结款项</div></td>
                            </tr>
                            <tr>
                                <td><input type="checkbox" name="fundcheck"></td>
                                <td><img src="../../images/jn.jpg"><span>小白兔</span></td>
                                <td>流出平台</td>
                                <td>确认收货</td>
                                <td>42</td>
                                <td>2017-7-30</td>
                                <td><div class="layui-btn layui-btn-danger  layui-btn-small fundclose">冻结款项</div></td>
                            </tr>
                            <tr>
                                <td><input type="checkbox" name="fundcheck"></td>
                                <td><img src="../../images/mm.jpg"><span>小蜜蜂</span></td>
                                <td>流入平台</td>
                                <td>发布快递单</td>
                                <td>32</td>
                                <td>2017-8-3</td>
                                <td><div class="layui-btn layui-btn-danger  layui-btn-small fundclose">冻结款项</div></td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="layui-btn layui-btn-danger  layui-btn-small closeall" id="fundcloseall">批量冻结</div>

                </div>
            </div>
            <!--底部导航-->
            <div class="layui-footer footer footer-demo" id="admin-footer"></div>
            <!--JS模块-->
            <script type="text/javascript" src="../../layui/layui.js"></script>
            <script src="../../js/jquery-1.12.3.min.js"></script>
            <script src="../../js/index.js"></script>
            <script type="text/javascript" src="../../js/jquery.cookie.js"></script>
            <!-- DataTables JavaScript -->
            <script src="../../datatables/media/js/jquery.dataTables.min.js"></script>
            <script type="text/javascript">
            var data = {
                "code": 200,
                "userVo": [{
                    "userId": 333,
                    "sex": "女",
                    "headPortraitUrl": "../../images/1.jpg",
                    "nickname": "zylin",
                    "username": "15967176622",
                    "userState": "使用中",
                    "lastLoginTime": "2017-7-8",
                    "userRegisterTime": "2017-7-8",
                    "integralScore": 59,
                    "creditScore": 99
                }, {
                    "userId": 111,
                    "sex": "女",
                    "headPortraitUrl": "../../images/0.jpg",
                    "nickname": "zylin",
                    "username": "15967176611",
                    "userState": "使用中",
                    "lastLoginTime": "2017-7-8",
                    "userRegisterTime": "2017-7-8",
                    "integralScore": 598,
                    "creditScore": 959
                }, {
                    "userId": 222,
                    "sex": "女",
                    "headPortraitUrl": "../../images/6.jpg",
                    "nickname": "linzy",
                    "username": "15967176633",
                    "userState": "使用中",
                    "lastLoginTime": "2017-7-8",
                    "userRegisterTime": "2017-7-8",
                    "integralScore": 69,
                    "creditScore": 122
                }]
            }

            $(function() {
                $("#fund").addClass('layui-this'); //对应订单管理的背景色
                $('#fundTable').DataTable({
                    responsive: true,
                    ordering: false,
                    searching: true,
                    "bLengthChange": false,
                    "bRetrieve": true,
                    "bFilter": true //过滤功能
                });
                // fundSelectChange(1);
                adminCookie();
            })


            function fund_Detail(fundid) {
                window.location.href = "funddetail.html?fundid=" + fundid;
            }


            $(document).on('click', '.fundclose', function() {
                k = $(this).parents("tr").index() + 1;
                var fundid = this.id
                var fundNickname = $(this).parents("tr").children('td:nth-child(4)').text()
                layui.use('layer', function() {
                    var layer = layui.layer;
                    layer.confirm('是否要冻结该款项?', {
                        icon: 2, 
                        title: '提示'
                    }, function(index) {
                        /*$.ajax({
                            type: "DELETE",
                            url: "/randomdelivery/AdminController/closeAccount/" + fundid,
                            data: {},
                            async: true,
                            dateType: "json",
                            contentType: "application/json",
                            success: function(data) {*/
                                if (data.code == 200) {
                                    $("table#fundTable").find("tr:eq(" + k + ")").children('td:nth-child(9)').text("已关闭").css('color', 'red');
                                    $("table#fundTable").find("tr:eq(" + k + ")").children('td:nth-child(10)').children('.fundclose').text("激活账号").attr('class', 'layui-btn layui-btn-normal  layui-btn-small wakeup');
                                    $("input[name='fundcheck']:checked").prop('checked', false)
                                    layer.close(index);
                                }
                            /*},
                            Error: function() {
                                alert("服务器出错");
                            }
                        })*/

                    });
                });
            });
                        $(document).on('click', 'tr td:not(:first)', function() {
                            if ($(this).siblings().first().children().is(':checked') == false) {
                                $(this).siblings().first().children().prop("checked", true);
                            } else {
                                $(this).siblings().first().children().prop("checked", false);
                            }
                        })


                        $("#fundcloseall").on('click', function() {
                            if ($("input[name='fundcheck']:checked").length == 0) {
                                layer.msg("请选择快递员")
                            } else {
                                layui.use('layer', function() {
                                    var layer = layui.layer;
                                    layer.confirm('是否要冻结选中款项？', {
                                        icon: 2,
                                        title: '提示'
                                    }, function(index) {
                                        $("input[name='fundcheck']:checked").each(function() {
                                            var element = this;
                                            if (!isNaN(element.id)) {

                                                /* $.ajax({
                                                     type: "DELETE",
                                                     url: "/randomdelivery/AdminController/closeAccount/" + element.id,
                                                     data: {},
                                                     async: true,
                                                     dateType: "json",
                                                     contentType: "application/json",
                                                     success: function(data) {*/
                                                if (data.code == 200) {
                                                    $(element).parents("tr").children('td:nth-child(9)').text("已冻结").css('color', 'red')
                                                    $(element).parents("tr").children('td:nth-child(10)').children('.fundclose').text("激活账号").attr('class', 'layui-btn layui-btn-normal  layui-btn-small wakeup');
                                                    $("input[name='fundcheck']:checked").prop('checked', false)
                                                    layer.close(index);
                                                }
                                                /*},
                                                    Error: function() {
                                                        alert("服务器出错");
                                                    }
                                                });*/
                                            }

                                        });
                                    });
                                });
                            }
                        })

                        $("#fundSequence").bind("change", function() {
                            fundSelectChange($(this).val())
                            alert(213)
                        })

                        function fundSelectChange(v) {
                            /*$.ajax({
                                type: "get",
                                url: "/randomdelivery/AdminController/users/pageCount/1/pageSize/10",
                                data: {
                                    "sequence": v,
                                },
                                async: true,
                                dateType: "json",
                                contentType: "application/json",
                                success: function(data) {*/
                            funddata(data);
                            /*},
                                Error: function() {
                                    alert("服务器出错");
                                }
                            })*/
                        }

                        function funddata(data) {
                            $('#fundTable').dataTable().fnClearTable(); //清除表格内
                            $.each(data.userVo, function(index, item) {
                                var state
                                var userRegisterTime = new Date(item.userRegisterTime).Format("yyyy-MM-dd hh:mm:ss")
                                var lastLoginTime = new Date(item.lastLoginTime).Format("yyyy-MM-dd hh:mm:ss")
                                k = index + 1
                                if (item.userState == 0) {
                                    state = "已冻结"
                                } else {
                                    state = "使用中"
                                }
                                $('#fundTable').dataTable().fnAddData([
                                    '<input type="checkbox" name="fundcheck" id="' + item.fundId + '">',
                                    '<img src=' + item.headPortraitUrl + '>',
                                    item.username,
                                    item.nickname,
                                    item.creditScore,
                                    item.integralScore,
                                    userRegisterTime,
                                    lastLoginTime,
                                    state,
                                    '<div class="layui-btn layui-btn-danger  layui-btn-small fundclose" id="' + item.fundId + '">冻结款项</div><div class="layui-btn  layui-btn-small fund_detail" onclick="fund_Detail(' + item.fundId + ')">详情</div>'
                                ]);
                                if (item.fundState == 0) {
                                    $("table#fundTable").find("tr:eq(" + k + ")").children('td:nth-child(9)').children('.fundclose').text("激活账号").attr('class', 'layui-btn layui-btn-normal  layui-btn-small wakeup').attr("id", item.fundId)
                                }
                            })
                        }

            </script>
            
        </div>
    </body>
</html>